import time
import unittest
import sys
sys.path.append(r'C:\Users\ZY\PycharmProjects\pythonProject')
from quote.web_test.login_case.HwTestReport import HTMLTestReportEN
from quote.base.usebrowser import UseBrowser
from quote.web_page.usermanager.login_page import LoginPage
from quote.web_test.usermanager.login_case.login_fail_test import LoginFailCase


class LoginSucCase(unittest.TestCase):

    def setUp(self):
        self.login_page = LoginPage()

    def test_1_admin_username_pwd_right(self):
        self.login_page.login('admin','123456')
        actual_info=self.login_page.get_suc_info()
        self.assertEqual(actual_info,'欢迎使用报价管理系统')

    def test_2_normal_username_pwd_right(self):
        self.login_page.login('admin', '123456')
        actual_info = self.login_page.get_suc_info()
        self.assertEqual(actual_info, '欢迎使用报价管理系统')

    def tearDown(self):
        UseBrowser.quit()


if __name__ == '__main__':
    # 测试套件
    suite = unittest.TestSuite()
    # 加载整个类的测试函数
    test_class_1 = unittest.TestLoader().loadTestsFromTestCase(LoginFailCase)
    test_class_2 = unittest.TestLoader().loadTestsFromTestCase(LoginSucCase)
    # 测试函数放到list中
    test_list = [test_class_1, test_class_2]
    # # 函数放到套件中
    suite.addTests(test_list)
    # 运行函数
    # runner = unittest.TextTestRunner(verbosity=0)
    report_time = time.strftime('%Y-%m-%d_%H-%M-%S')
    # 生成报告
    # with open('../../../report/report_' + report_time + '.html', 'wb+') as fp:
    with open('../../../report/report_'+report_time+'.html', 'wb+') as fp:
        runner = HTMLTestReportEN(stream=fp, verbosity=2,
                                  title='web auto quote',
                                  description='Test quote project')
        runner.run(suite)
    # # 执行套件
    # runner.run(suite)
